<?php

namespace App\Services;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class OrderService
{
    public function create(Model $model)
    {
        return $model->orders()->create([
            'user_id' => Auth::id(),
            'sn' => $this->getSn($model),
            'price' => $model->price,
            'pay_state' => false,
            'subject' => $model->title
        ]);
    }

    public function getSn(Model $model)
    {
        return Auth::id() . $model->id . '_' . time();
    }
}
